package com.demo.rmi.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RmiServer {

    private static final Logger logger = LoggerFactory.getLogger(RmiServer.class);

    public static void main(String[] args) throws RemoteException, AlreadyBoundException, MalformedURLException {
        HelloService helloService = new HelloService();
        UserService userService = new UserService();
        LocateRegistry.createRegistry(9999);
        Naming.bind("rmi://localhost:9999/helloRmi/h1",helloService);

      /*  LocateRegistry.createRegistry(9998);
        Naming.bind("rmi://localhost:9998/helloRmi",helloService);
        //Naming.bind("rmi://localhost:9999/helloRmi",helloService);
        Registry registry = LocateRegistry.getRegistry(9999);
        if (registry == null) {
            LocateRegistry.createRegistry(9999);
        }
        Naming.bind("rmi://localhost:9999/user",userService);*/
        logger.info("服务绑定成功");
    }
}
